package com.lagou.mapper;

import com.lagou.pojo.User;
import org.apache.ibatis.annotations.*;
import org.mybatis.caches.redis.RedisCache;

import java.util.List;

@CacheNamespace(implementation = RedisCache .class) //开启二级缓存
public interface IUserMapper {

    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "username",column = "username"),
            @Result(property = "orderList",column = "id",javaType = List.class,
                    many = @Many(select = "com.lagou.mapper.IOrderMapper.findOrderByUid"))
    })
    @Select("select * from user")
    public List<User> findAll();


    @Select("select * from user")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "username",column = "username"),
            @Result(property = "roleList",column = "id",javaType = List.class,
                    many = @Many(select = "com.lagou.mapper.IRoleMapper.findRoleByUid"))
    })
    public List<User> findAllUserAndRole();



    @Insert("insert into user values(#{id},#{username})")
    public void addUser(User user);

    @Update("update user set username = #{username} where id = #{id}")
    public void updateUser(User user);

    @Select("select * from user")
    public List<User> selectUser();

    @Delete("delete from user where id = #{id}")
    public void deleteUser(Integer id);


    //根据ID查用户
    @Select("select * from user where id = #{id}")
    public User findUserById(Integer id);
}
